package vip.afeng.screen;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.net.Inet4Address;
import java.net.UnknownHostException;

@SpringBootApplication
@EnableScheduling
@Controller
public class Starter {

	private static String hostAddress = null;
	private static String port = null;

	@RequestMapping({"","index","index.html"})
	public String getIndex(Model model) {
		model.addAttribute("hostAddress", hostAddress);
		return "index";
	}
	public static void main(String[] args) {

		SpringApplicationBuilder builder = new SpringApplicationBuilder(Starter.class);
		builder.headless(false);
		builder.run(args);
		// 打印本地ip
		try {
			hostAddress = Inet4Address.getLocalHost().getHostAddress();
			System.out.println(hostAddress+":"+port);
		} catch (UnknownHostException e) {
			System.out.println(" = " + "主机未知");
		}

//		SpringApplication.run(Application.class, args);
	}

	@Value("${server.port}")
	public void setPort(String port){
		this.port = port;
	}

}
